home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 03 / drag / burnit.c next >
Text File  |  1992-05-01  |  5KB  |  158 lines

  1. /****************************************************************************
  2. Module name: BurnIt.C
  3. Programmer : Jeffrey M. Richter.
  4. Description: Drop File Client Sample Application.
  5. *****************************************************************************/
  6.  
  7. #include <windows.h>
  8. #include <mmsystem.h>
  9. #include <shellapi.h>
  10.  
  11. extern HINSTANCE _cdecl _hInstance;
  12.  
  13. //****************** PROTOTYPES FOR LOCAL FUNCTIONS *************************/
  14. LRESULT FAR BurnItWndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  15.  
  16.  
  17. //************************ GLOBAL VARIABLES *********************************/
  18. char _szAppName[] = "BurnIt";
  19.  
  20. #define BURNICONS     2
  21. #define FLAREICONS    3
  22. #define MAX_ICONS     (BURNICONS + FLAREICONS)
  23.  
  24. #define ICON_First   100
  25.  
  26. HICON hIconList[MAX_ICONS];
  27. int _nIconNum;        // Index into hIcons of last displaed icon
  28. BOOL _fFlaring = FALSE;
  29.  
  30. #pragma argsused
  31. int WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  32.                     LPSTR lpszCmdLine, int nCmdShow) {
  33.    MSG msg;
  34.    HWND hWnd;
  35.    WNDCLASS wc;
  36.  
  37.    if (hPrevInstance != NULL) {
  38.       // If instance of BurnIt is already running, bring it to top and
  39.       // terminate this instance
  40.       BringWindowToTop(FindWindow(_szAppName, _szAppName));
  41.       return(0);
  42.    }
  43.  
  44.    wc.style = 0;
  45.    wc.lpfnWndProc = (WNDPROC) BurnItWndProc;
  46.    wc.cbClsExtra = wc.cbWndExtra = 0;
  47.    wc.hInstance = hInstance;
  48.    wc.hIcon = NULL;
  49.    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  50.    wc.hbrBackground = NULL;
  51.    wc.lpszMenuName = NULL;
  52.    wc.lpszClassName = _szAppName;
  53.    if (!RegisterClass(&wc)) return(0);
  54.  
  55.    // Create the Frame window.
  56.    hWnd = CreateWindowEx(WS_EX_ACCEPTFILES, _szAppName, _szAppName,
  57.                          WS_OVERLAPPED | WS_VISIBLE |
  58.                          WS_CAPTION | WS_SYSMENU,
  59.                          CW_USEDEFAULT, SW_MINIMIZE,
  60.                          CW_USEDEFAULT, CW_USEDEFAULT,
  61.                          NULL, NULL, hInstance, NULL);
  62.    if (hWnd == NULL) return(0);
  63.  
  64.    while (GetMessage(&msg, NULL, 0, 0))
  65.       {
  66.       TranslateMessage(&msg);
  67.       DispatchMessage(&msg);
  68.       }
  69.  
  70.    return(msg.wParam);
  71. }
  72.  
  73.  
  74. LRESULT FAR BurnItWndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  75. {
  76.    BOOL fCallOrigProc = FALSE;
  77.    LRESULT lResult = 0;
  78.    WORD wFilesDropped, wSize;
  79.    NPSTR npszPathName;
  80.    OFSTRUCT of;
  81.    HDC hDC;
  82.    WORD x;
  83.  
  84.    switch (Msg) {
  85.  
  86.       case WM_CREATE:
  87.          SetWindowPos(hWnd, HWND_TOPMOST,
  88.             0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  89.          SetTimer(hWnd, 1, 250, NULL);
  90.          for (x = 0; x < MAX_ICONS; x++)
  91.              {
  92.              hIconList[x] = LoadIcon(_hInstance,
  93.                                      MAKEINTRESOURCE(ICON_First + x));
  94.              }
  95.          break;
  96.  
  97.       case WM_DESTROY:
  98.          KillTimer(hWnd, 1);
  99.          PostQuitMessage(0);
  100.          break;
  101.  
  102.       case WM_QUERYOPEN:
  103.          // Don't allow this app to be opened. It only runs as an icon.
  104.          lResult = FALSE;
  105.          break;
  106.  
  107.       case WM_TIMER:
  108.          x = _nIconNum + 1;
  109.          x = x % (int) (_fFlaring ? MAX_ICONS : BURNICONS);
  110.          if (x == 0)
  111.             _fFlaring = 0; // Reset to burning only
  112.          _nIconNum = x;
  113.  
  114.          hDC = GetDC(hWnd);
  115.          SendMessage(hWnd, WM_ERASEBKGND, hDC, 0);
  116.          DrawIcon(hDC, 0, 0, hIconList[x]);
  117.          ReleaseDC(hWnd, hDC);
  118.          break;
  119.  
  120.       case WM_DROPFILES:
  121.          _fFlaring = TRUE; // Stoke the fire!
  122.          sndPlaySound("Siren.Wav", SND_ASYNC);
  123.  
  124.          // Get the number of pathnames that are being dropped on us
  125.          wFilesDropped = DragQueryFile((HDROP) wParam, -1, NULL, 0);
  126.  
  127.          while (wFilesDropped-- > 0)
  128.             {
  129.             // Get the length of the the pathname
  130.             wSize = DragQueryFile((HDROP) wParam, wFilesDropped, NULL, 0) + 1;
  131.  
  132.             // Allocate a block of memory large enough for the pathname
  133.             npszPathName = (NPSTR) LocalAlloc(LMEM_FIXED, wSize);
  134.             if (npszPathName == NULL) continue; // Insufficient memory
  135.  
  136.             // Copy the pathname into our local buffer
  137.             DragQueryFile((HDROP) wParam, wFilesDropped, npszPathName, wSize);
  138.  
  139.             // Delete this file
  140.             OpenFile(npszPathName, &of, OF_DELETE);
  141.  
  142.             LocalFree((HLOCAL) npszPathName);
  143.             }
  144.  
  145.          // Free the memory block containing the pathnames
  146.          DragFinish((HDROP) wParam);
  147.          break;
  148.  
  149.       default:
  150.          fCallOrigProc = TRUE;
  151.          break;
  152.    }
  153.    if (fCallOrigProc)
  154.       lResult = DefWindowProc(hWnd, Msg, wParam, lParam);
  155.  
  156.    return(lResult);
  157. }
  158.